<%
	/*
		对象原生方法/属性
			属性:
			方法:
		对象扩展方法及属性
			属性:
			方法:
			静态方法:
	*/
	/* @扩展方法 */
		//->返回格式化的字符串
		Date.prototype.toCommString=function($options)
		{
			return Date.toCommString(this,$options);
		};
		//->返回日期对象某部分的值	
		Date.prototype.year=function($isUTC)
		{
			return Date.part(this,'year',$isUTC);	
		};
		Date.prototype.month=function($isUTC)
		{
			return Date.part(this,'month',$isUTC);	
		};
		Date.prototype.date=function($isUTC)
		{
			return Date.part(this,'date',$isUTC);	
		};
		Date.prototype.day=function($isUTC)
		{
			return Date.part(this,'day',$isUTC);	
		};		
		Date.prototype.hour=function($isUTC)
		{
			return Date.part(this,'hour',$isUTC);	
		};
		Date.prototype.minute=function($isUTC)
		{
			return Date.part(this,'minute',$isUTC);	
		};		
		Date.prototype.second=function($isUTC)
		{
			return Date.part(this,'second',$isUTC);	
		};	
		Date.prototype.milliSecond=function($isUTC)
		{
			return Date.part(this,'millisecond',$isUTC);	
		};		
		//->判定闰年
		Date.prototype.isLeap=function($isUTC)
		{
			var _tYear=($isUTC==true||$isUTC=='UTC') ? (this.getUTCFullYear()):(this.getFullYear());
			return (_tYear%400==0)||((_tYear%100!=0)&&(_tYear%4==0));	
		};	
		//->比较时间对象与指定时间对象这间的差
		Date.prototype.diff=function($datepart,$endDate)
		{
			return Date.diff($datepart,this,$endDate);
		};			
		//->在时间对象上偏移
		Date.prototype.add=function($datepart,$number)
		{
			return Date.add($datepart,$number,this);
		};		
	/* @静态方法 */
		//->取现在时间
		Date.now=function()
		{
			return new Date();	
		};	
		//->解析日期对象或字符串，并返回日期对象
		Date.analyse=function($date)
		{		
			//->String
			//YYYY-MM-DD(,|space)HH:MM:SS
			//YYYY/MM/DD(,|space)HH:MM:SS					
			//MM-DD-YY(,|space)HH:MM:SS
			//MM/DD/YY(,|space)HH:MM:SS
			//July 10 1995 10:00 PM
			//Mon Jul 10 5:00:00 PM UTC+0800 1995
			switch(varType($date))
			{
				case 'string':
					$date=String.trim($date);
					if(isNaN(Date.parse($date))==true)
					{	
						if(cuDateTimeRegexp.test($date)==true)
						{
							var _ta=($date.indexOf(',')!=-1) ? ($date.split(',')):($date.split(' '));
							var _taDate=_ta[0].split('-');
							var _taTime;
								try{
									_taTime=_ta[1].split(':');		
								}catch(e){
									_taTime=[];
								}
							if(_taTime=='') _taTime=[0];
							var _ts=_taDate[1]+'/'+_taDate[2]+'/'+_taDate[0];
							(_taTime[0]!=null) ? (_ts+=','+_taTime[0]) : (_ts+=',0');
							(_taTime[1]!=null) ? (_ts+=':'+_taTime[1]) : (_ts+=':0');
							(_taTime[2]!=null) ? (_ts+=':'+_taTime[2]) : (_ts+=':0');
							return new Date(_ts);
						}
					}
					else
						return new Date($date);
					break;
				case 'date':
					return new Date($date)
					break;
				default:
					return NaN;
			};
		};			
		//->比较两日期之间的差值
		Date.diff=function($datepart,$startDate,$endDate)
		{
			$datepart=$datepart.toLowerCase();
			$startDate=Date.analyse($startDate);
			$endDate=Date.analyse($endDate);
			if($datepart!=undefined&&(isNaN($startDate)==false&&isNaN($endDate)==false))
			{
				var dateSign=1,tempDate;				
				var timeRes=Date.parse($endDate)-Date.parse($startDate);				
				if(timeRes.isNegative()==true)
				{
					tempDate=$startDate;
					$startDate=$endDate;
					$endDate=tempDate;
					dateSign=-1;
					timeRes=Date.parse($endDate)-Date.parse($startDate);
				}
				if($datepart=='m'||$datepart=='month'||$datepart=='y'||$datepart=='year')
				{
					var timeResYear=0;
					var leapYear=0;
					(($endDate.getFullYear()-$startDate.getFullYear())+1).times
					(
						function($n)
						{
							if((new Date('1/'+'1/'+($startDate.getFullYear()+$n))).isLeap())
							{
								leapYear++;	
							};							
						}
					)
					timeResYear=(((timeRes-leapYear.floor()*366*24*60*60*1000)/1000/60/60/24/365)+leapYear.floor()).toInteger();				
				}
				if($datepart=='y'||$datepart=='year')
				{
					return (dateSign==-1) ? timeResYear*-1 : timeResYear;
				}
				else if($datepart=='m'||$datepart=='month')
				{
					var timeResMonth=timeResYear*12;
					return  (dateSign==-1) ? (timeResMonth*-1):(timeResMonth);
				}
				else if($datepart=='d'||$datepart=='date'||$datepart=='day')
				{
					var timeResDay=timeRes/1000/60/60/24;
					return (dateSign==-1) ? (timeResDay*-1):(timeResDay);
				}
				else if($datepart=='h'||$datepart=='hour')
				{
					var timeResHour=timeRes/1000/60/60;
					return (dateSign==-1) ? (timeResHour*-1):(timeResHour);
				}
				else if($datepart=='mm'||$datepart=='minute')
				{
					var timeResMinute=timeRes/1000/60;
					return (dateSign==-1) ? (timeResMinute*-1):(timeResMinute);
				}
				else if($datepart=='s'||$datepart=='second')
				{
					var timeResSecond=timeRes/1000;
					return (dateSign==-1) ? (timeResSecond*-1):(timeResSecond);
				}
				else if($datepart=='ms'||$datepart=='millisecond')
					return (dateSign==-1) ? (timeRes*-1):(timeRes);
				else
					return NaN;		
			}
			else
			{
				return NaN;
			};
		};
		//->在指定时间值上进行偏移
		Date.add=function($datepart,$number,$date)
		{
			$datepart=$datepart.toLowerCase();
			$date=Date.analyse($date);
			if($datepart!=undefined&&(isNaN($date)==false&&isNumeric($number,'integer')==true))
			{
				if($datepart=='y'||$datepart=='year')
				{
					$date.setFullYear($date.getFullYear()+$number);
					return $date;
				}
				else if($datepart=='m'||$datepart=='month')
				{
					$date.setMonth($date.getMonth()+$number);
					return $date;
				}
				else if($datepart=='d'||$datepart=='date'||$datepart=='day')
				{
					$date.setDate($date.getDate()+$number);
					return $date;
				}
				else if($datepart=='h'||$datepart=='hour')
				{
					$date.setHours($date.getHours()+$number);						
					return $date;
				}
				else if($datepart=='mm'||$datepart=='minute')
				{
					$date.setMinutes($date.getMinutes()+$number)
					return $date;
				}
				else if($datepart=='s'||$datepart=='second')
				{
					$date.setSeconds($date.getSeconds()+$number)
					return $date;
				}
				else if($datepart=='ms'||$datepart=='millisecond')
				{
					$date.setMilliseconds($date.getMilliseconds()+$number)
					return $date;
				}
				else
					return NaN;		
			}
			else
			{
				return NaN;
			};
		};	
		//->返回日期对象某部分的值
		Date.part=function($dateobj,$datepart,$isUTC)
		{	
			var tValue='';
			$datepart=$datepart.toLowerCase();
			$isUTC=(varType($isUTC)=='string') ? ($isUTC.toUpperCase()):($isUTC);
			if($datepart=='y'||$datepart=='year')
				tValue=($isUTC==true||$isUTC=='UTC') ? ($dateobj.getUTCFullYear().toPaddedString(2)) : ($dateobj.getFullYear().toPaddedString(2));
			else if($datepart=='m'||$datepart=='month')
				tValue=($isUTC==true||$isUTC=='UTC') ? (($dateobj.getUTCMonth()+1).toPaddedString(2)) : (($dateobj.getMonth()+1).toPaddedString(2));
			else if($datepart=='d'||$datepart=='date')
				tValue=($isUTC==true||$isUTC=='UTC') ? ($dateobj.getUTCDate().toPaddedString(2)) : ($dateobj.getDate().toPaddedString(2));	
			else if($datepart=='dd'||$datepart=='day')
				tValue=($isUTC==true||$isUTC=='UTC') ? ($dateobj.getUTCDay().toPaddedString(2)) : ($dateobj.getDay().toPaddedString(2));	
			else if($datepart=='h'||$datepart=='hour')
				tValue=($isUTC==true||$isUTC=='UTC') ? ($dateobj.getUTCHours().toPaddedString(2)) : ($dateobj.getHours().toPaddedString(2));
			else if($datepart=='mm'||$datepart=='minute')
				tValue=($isUTC==true||$isUTC=='UTC') ? ($dateobj.getUTCMinutes().toPaddedString(2)) : ($dateobj.getMinutes().toPaddedString(2));
			else if($datepart=='s'||$datepart=='second')
				tValue=($isUTC==true||$isUTC=='UTC') ? ($dateobj.getUTCSeconds().toPaddedString(2)) : ($dateobj.getSeconds().toPaddedString(2));
			else if($datepart=='ms'||$datepart=='millisecond')
				tValue=($isUTC==true||$isUTC=='UTC') ? ($dateobj.getUTCMilliseconds().toPaddedString(2)) : ($dateobj.getMilliseconds().toPaddedString(2));				
			else
				tValue=NaN;			
			return tValue;
		};
		Date.name=Date.part	
		//->返回各种形式的日期字符串
		Date.toCommString=function($date,$options)
		{
			//->String
			//options {foramt,isHaveTime:}
			//YYYY-MM-DD(,|space)HH:MM:SS
			//YYYY/MM/DD(,|space)HH:MM:SS					
			//MM-DD-YY(,|space)HH:MM:SS
			//MM/DD/YY(,|space)HH:MM:SS
			//July 10 1995 10:00 PM
			//Mon Jul 10 5:00:00 PM UTC+0800 1995
			var objVarType=varType($date);
				$options=($options||{format:' ',isHaveTime:false,ls:' '});
			if(objVarType=='string'||objVarType=='date')
			{
				var tObj=(objVarType=='string') ? (Date.analyse($date)):($date);	
				var tText='';
				if(isNaN(tObj)==true)
					return undefined;
				else
				{
					var tDateText_YMD=tObj.year()+'-'+tObj.month()+'-'+tObj.date();
					var tDateText_MDY=tObj.month()+'-'+tObj.date()+'-'+tObj.year();						
					var tTimeText=tObj.hour()+':'+tObj.minute()+':'+tObj.second();	
					switch($options.format.toUpperCase())
					{
						case 'YMD -':
							tText=tDateText_YMD;
							if($options.isHaveTime==true) tText+=$options.ls+tTimeText;
							break;
						case 'YMD /':
							tText=tDateText_YMD.replace(/-/g,'/');
							if($options.isHaveTime==true) tText+=$options.ls+tTimeText;
						case 'MDY -':
							tText=tDateText_MDY;
							if($options.isHaveTime==true) tText+=$options.ls+tTimeText;
							break;
						case 'MDY /':
							tText=tDateText_MDY.replace(/-/g,'/');
							if($options.isHaveTime==true) tText+=$options.ls+tTimeText;
							break;									
						default:
							tText=tDateText_YMD+$options.ls+tTimeText;
					}
				}
				tObj=null;
				return tText;
			}
			else
				return undefined;		
		};			
%>